#include<iostream>
#include<unordered_map>
#include<unordered_set>
using namespace std;

void solve()
{
	int ma[505][505] = { 0 };
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			int temp; cin >> temp;
			if (temp >= 0) continue;
			if (i > j) ma[i - j][0] = max(ma[i - j][0], abs(temp));
			else ma[0][j - i] = max(ma[0][j - i], abs(temp));
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) ans += ma[i][j];
	}
	cout << ans << endl;
	return;
}

int main()
{
	int t; cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}